package com.sxpcwlkj.authority.listener;


import cn.dev33.satoken.listener.SaTokenListener;
import cn.dev33.satoken.stp.SaLoginModel;
import cn.dev33.satoken.stp.StpUtil;
import com.sxpcwlkj.common.enums.DeviceEnum;
import com.sxpcwlkj.redis.RedisUtil;
import com.sxpcwlkj.redis.constant.RedisConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * 自定义侦听器的实现
 * @author mmsAdmin
 */
@Component
@Slf4j
public class MySaTokenListener implements SaTokenListener {


    /**
     * 每次登录时触发
     */
    @Override
    public void doLogin(String s, Object o, String s1, SaLoginModel saLoginModel) {
        log.info("doLogin");
    }

    /**
     * 每次注销时触发
     */
    @Override
    public void doLogout(String s, Object o, String s1) {
        String device = StpUtil.getLoginDevice();
        if(DeviceEnum.MOBILE.getType().equals(device)){
            RedisUtil.deleteObject(RedisConstant.MOBILE_KEY+o.toString());
        }
        if (DeviceEnum.ADMIN.getType().equals(device)){
            RedisUtil.deleteObject(RedisConstant.ADMIN_KEY+o.toString());
        }

    }

    @Override
    public void doKickout(String s, Object o, String s1) {

    }

    /**
     * 每次被顶下线时触发
     */
    @Override
    public void doReplaced(String s, Object o, String s1) {

    }

    @Override
    public void doDisable(String s, Object o, String s1, int i, long l) {

    }

    @Override
    public void doUntieDisable(String s, Object o, String s1) {

    }

    @Override
    public void doOpenSafe(String s, String s1, String s2, long l) {

    }

    @Override
    public void doCloseSafe(String s, String s1, String s2) {

    }

    @Override
    public void doCreateSession(String s) {

    }

    @Override
    public void doLogoutSession(String s) {

    }

    @Override
    public void doRenewTimeout(String s, Object o, long l) {

    }
}


